package com.control;

import com.dao.QuestionDao;
import com.dao.QuestionDaoImpl;
import com.model.Question;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/exam.do")
public class ExamServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        QuestionDao questionDao = new QuestionDaoImpl();
        int n = 5;
        ArrayList<Question> questions = null;
        questions = questionDao.getQuestions(n);
        HttpSession httpSession = request.getSession();
        httpSession.setAttribute("n", n);
        httpSession.setAttribute("questions", questions);
        response.sendRedirect("exam.jsp");
    }
}
